package edu.gatech.bsbmule.model;

import java.util.Random;


/**
 * This class represents the Pub, where players can win money based
 * on the round and their time bonus.
 * 
 * @author Melissa
 * @version 1.0 10/26/13
 *
 */
public class Pub {
	private Random rand;
	
	public Pub() {
		this.rand = new Random();
	}
	
	/**
	 * Calculates money bonus that player wins when he gambles (max 250)
	 * 
	 * @return money gained
	 */
	public int calculateBonus() {
		int moneyGained = getRoundBonus() * getTimeBonus();
		if (moneyGained > 250) {
			moneyGained = 250;
		}
		return moneyGained;
	}
	
	/**
	 * Gets round bonus based on current round of game
	 * 
	 * @return round bonus
	 */
	private int getRoundBonus() {
		int roundBonus = 0;
		int round = Game.getInstance().getCurrentRound();
		if (round >= 1 && round <= 3) {
			roundBonus = 50;
		} else if (round >= 4 && round <= 7) {
			roundBonus = 100;
		} else if (round >= 8 && round <= 11) {
			roundBonus = 150;
		} else if (round == 12) {
			roundBonus = 200;
		}
		return roundBonus;
	}
	
	/**
	 * Gets a random number between 0 and the time bonus, which is
	 * based on amount of time player has remaining in his turn
	 * 
	 * @return time bonus
	 */
	private int getTimeBonus() {
		int timeBonus = 50;
		int remainingTime = 
				(int)(CustomizedTimer.getInstance().getRemainingTime() / 1000);
		
		if (remainingTime >= 0 && remainingTime < 12) {
			timeBonus = 50;
		} else if (remainingTime >= 12 && remainingTime < 25) {
			timeBonus = 100;
		} else if (remainingTime >= 25 && remainingTime < 37) {
			timeBonus = 150;
		} else if (remainingTime >= 37 && remainingTime <= 50) {
			timeBonus = 200;
		}
		int randomNum = rand.nextInt(timeBonus);
		return randomNum;		
	}
}
